define(function(require, exports, module) {
  var tool = require("tool");
  var log = require("log");
  
  var a = function(startHref,rooturl,moduleName){
    if(location.href==startHref){
      return;
    }
    (function(m, o, d, u, l, a, r) {
      if(m[d]) return;
      function f(n, t) { return function() { r.push(n, arguments); return t } }
      m[d] = a = { args: (r = []), config: f(0, a), use: f(1, a) };
      m.define = f(2);
      u = o.createElement('script');
      u.id = d + 'node';
      u.src = rooturl+'lib/sea.js';
      l = o.getElementsByTagName('head')[0];
      a = o.getElementsByTagName('base')[0];
      a ? l.insertBefore(u, a) : l.appendChild(u);
    })(window, document, 'seajs');
    
    seajs.config({
      base:rooturl
    });
    
    seajs.use([moduleName],function(m){});  
  }
  
  exports.onLink = function ($link){
    var href = $link.attr('href');
    var moduleName = $link.attr('mpara');
    var script = "("+a.toString()+")('"+location.href+"','"+tool.rooturl+"','"+moduleName+"')";
    log(script);
    exports.set(script);
    location.href = href;
  };
  
  exports.set = function(script){
    if(tool.isChrome) return;
    cordova.exec(
      function(winParam) {log("inject "+winParam);}, 
      function(error) {log("inject "+error)}, 
      "Injectjs",
      "set", 
      [script]
    );
  }
});